<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/add.css"/>
	</head>
	<body>
		<div id="app">
			<div class="header">
				<span>修改用户</span>
			</div>
			<div class="content">
				<table>	
					<tr>
						<td class="text-right">手机号码</td><td class="content_right"><input class="input inline-input" placeholder="请输入手机号码" id="phone"> <span class="btn btn-info" id="find">立即查找</span></td>
					</tr>
				</table>
			</div>
			
			
			<div class="header">
				<span>查找信息如下</span>
			</div>
			<div class="content">
				<table>
					<tr>
						<td class="text-right">姓名</td><td class="content_right"><input class="input" placeholder="请输入姓名"></td>
					</tr>
					<tr>
						<td class="text-right">手机号码</td><td class="content_right"><input name="phone" class="input" placeholder="请输入手机号码" onblur="checkPhone()"></td>
					</tr>
						<td class="text-right">密码</td><td class="content_right"><input name="password" class="input" placeholder="请输入密码" onblur="checkPassword()"></td>
					</tr>
					<tr>
						<td></td><td class="content_right"><span class="btn btn-info" id="update">立即修改</span> <span class="btn">重置</span> </td>
					</tr>
				</table>
			</div>
		</div>
	</body>
	<script src="/qrcode/jquery2.1.4.js"></script>
	<script src="/layer/layer.js"></script>
	<script>


		// 验证密码 6-18位 只包含数字和字母
		function checkPassword(){
			var pattern = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z\\W]{6,18}$/;
			var password = document.getElementsByName("password")[0].value;
			if (password.match(pattern) == null){
				alert("请输入6-18位只包含数字和字母的密码");
			}else
				console.log("password="+password);
		}

		// 验证手机号
		// 0?(13|14|15|18)[0-9]{9}
		function checkPhone(){
			var pattern = /^0?(13|14|15|18)[0-9]{9}$/;
			var phone = document.getElementsByName("phone")[0].value;
			if (phone.match(pattern) == null){
				alert("请输入以13，14，15，18开头的11位的手机号");
			}else
				console.log("phone="+phone);

		}
	</script>
	<script>
		$(".header:eq(1),.content:eq(1)").hide();
		var old_phone = $("#phone").val();
		$(function(){
			$("#find").click(function(){
				var windowId = layer.load();
				var phone = $("#phone").val();

				$.getJSON("/user/find.do",{phone:phone},function(data){
					layer.close(windowId);
					//{"status":0,"result":"查询成功","data":{"id":5,"name":"55","phone":"55","ID_Card":"55","password":"55","numberOfPackages":5,"createTime":"Apr 6, 2021, 9:00:04 AM","loginTime":"Apr 6, 2021, 9:00:06 AM"}}
					layer.msg(data.result);
					if(data.status == 0){
						$(".header:eq(1),.content:eq(1)").fadeIn(1000);
						$("input:eq(1)").val(data.data.name);
						$("input:eq(2)").val(data.data.phone);
						$("input:eq(3)").val(data.data.password);
					}
				})
			});

			$("#update").click(function(){
				var windowId = layer.load();
				var name = $("input:eq(1)").val();
				var phone = $("input:eq(2)").val();
				var password = $("input:eq(3)").val();

				var user = {
					name:name,
					password:password
				};
				if (old_phone != phone){
					user.phone = phone;
				}

				$.getJSON("/user/update.do",user,function(data){
					layer.close(windowId);
					layer.msg(data.result)

					if(data.status == 0){
						//修改成功
						$(".header:eq(1),.content:eq(1)").hide();
					}
				})
			});
		});
	</script>
</html>
